package br.com.hd.dao;

import java.security.NoSuchAlgorithmException;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;

import br.com.hd.entity.Responsavel;
import br.com.hd.util.Encripty;
import br.com.hd.util.HibernateUtility;

public class ResponsavelDAO extends DAO {

	private static ResponsavelDAO instance;

	private ResponsavelDAO() {
	}
	
	public static ResponsavelDAO getInstance() {
		if (instance == null) {
			instance = new ResponsavelDAO();
		}
		return instance;
	}

	public Responsavel autentica(Responsavel responsavel) throws NoSuchAlgorithmException {
		HibernateUtility.beginTransaction();
		Criteria c = HibernateUtility.getSession()
				.createCriteria(Responsavel.class);
		c.add(Restrictions.eq("email", responsavel.getEmail().toLowerCase()));
		c.add(Restrictions.eq("senha",
				Encripty.criptografaSenha(responsavel.getSenha())));
		//HibernateUtility.commitTransaction();
		return (Responsavel) c.uniqueResult();
	}
	

}